import { ref, defineEmits, onMounted } from "vue";

//dialog组件本身
function dialogEvent(dom: any, params: object) {
  dom = ref(null);
  const open = (params: object) => {
    dom.value.show(params || null);
  };
  return {
    dom,
    open,
  };
}
//调用dialog事件
function useDialogEvent(
  api: (n: any) => any,
  form: object,
  eventName: Array<string>,
) {
  const dialogVisible = ref(false);
  const show = (data: object) => {
    dialogVisible.value = true;
    for (let x in form) {
      form[x] = data[x];
    }
  };
  const a = defineEmits(["success"]);
  const submit = async () => {
    const res = await api(form);
    // emits("success");
  };
  const cancel = () => {
    dialogVisible.value = false;
  };
  return {
    show,
    submit,
    cancel,
    dialogVisible,
    // emits
  };
}
export { useDialogEvent, dialogEvent };
